import java.util.Deque;
import java.util.LinkedList;

public class Solution1700 {
    public int countStudents(int[] students, int[] sandwiches) {
        Deque<Integer> queue1=new LinkedList<>();
        Deque<Integer> queue2=new LinkedList<>();
        for (int student : students) {
            queue1.addLast(student);
        }
        for (int sandwich : sandwiches) {
            queue2.addLast(sandwich);
        }
        for (int i=0;i<10000;i++){
            if (queue1.isEmpty()){
                break;
            }
            if (queue1.getFirst().equals(queue2.getFirst())){
                queue1.removeFirst();
                queue2.removeFirst();
            }else {
                queue1.addLast(queue1.removeFirst());
            }
        }
        return queue1.size();
    }

    public static void main(String[] args) {
        System.out.println(new Solution1700().countStudents(new int[]{1,1,0,0},new int[]{0,1,0,1}));
    }
}
